package com.taplinker.client.im.rpc.body;

import java.util.Date;

import com.taplinker.client.im.protocol.ConsultEntriy;
import com.taplinker.client.im.protocol.TapLinkerConversation;

public class ConvertUtil {
	
	public static TapLinkerConversation convertToConversation(Cmd004Rep value) {
		TapLinkerConversation conversation = new TapLinkerConversation();
		conversation.setCreateDate(new Date(value.getUpdateDate()));
		conversation.setCustomerId(value.getCustomerId());
		conversation.setCustomerName(value.getCustomerName());
		conversation.setId(value.getId());
		conversation.setLastMessage(value.getLastMessage());
		conversation.setMessageType(value.getMessageType());
		conversation.setVisitor(value.getVisitor());
		conversation.setAppName(value.getAppName());
		conversation.setUnreadMessages(value.getUnreadMessages());
		conversation.setType(value.getType());
		conversation.setSource(value.getSource());
		conversation.setSourceDetail(value.getSourceDetail());
		conversation.setLocal(value.getLocal());

		if (conversation.getUpdateDate() == null) {
			conversation.setUpdateDate(conversation.getCreateDate());
		}

		ConsultEntriy entriy = new ConsultEntriy();
		entriy.setDescription(value.getProduct().getDescription());
		entriy.setPicture(value.getProduct().getPicture());
		entriy.setProductId(value.getProduct().getProductId());
		entriy.setProductName(value.getProduct().getProductName());

		conversation.setProduct(entriy);
		return conversation;
	}
	
}
